const app = getApp();
const http = require('../../utils/http.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    customerName: '',
    userInfo: null,
    isModal: false
  },
  getUserProfile(e){
    wx.getUserProfile({
      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        app.globalData.userInfo = res.userInfo;
        console.log(res)
        this.setData({
          isModal: true
        })
      }
    })
  },
  // onGetUserInfo: function (e) {
  //   console.log(e)
  //   if (e.detail.userInfo) {
  //     app.globalData.userInfo = e.detail.userInfo;
  //     this.setData({
  //       isModal: true
  //     })
  //   }
  // },
  onGetPhoneNumber: function (e) {
    //console.log(e)
    //console.log(e.detail.encryptedData)
    //console.log(app.globalData.userInfo)
    let postData = Object.assign(app.globalData.userInfo, {ivStr: e.detail.iv}, {encryptedData: e.detail.encryptedData});
    //console.log(postData)
    http.post('/api/user/add', postData).then(res => {
      if (res.code == 200) {
        app.globalData.userInfo = res.data
        wx.setStorageSync('userInfo', app.globalData.userInfo)
        wx.navigateBack({
          delta: 1
        })
      }
    })
  },
  hideModal: function (e) {
    this.setData({
      isModal: false
    })
  },
  toIndex(){
    wx.reLaunch({
      url: '/pages/index/index'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      customer: app.globalData.customer
    })
    this.setData({
        customerName: app.globalData.customer.name
    })
  },

})
